package com.webas.api.service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import com.webas.api.entity.Entity;

public class ServiceFactory
{

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static <T extends Entity<?>> Service<T> create(Class<T> entityType) {
	
		try {
	
			ServiceProxy proxy = new ServiceProxy(entityType);
	
			Class<?> proxyClass = (Class<?>) Proxy.getProxyClass(ServiceProxy.class.getClassLoader(), Service.class);
			Service<T> service = (Service<T>) proxyClass.getConstructor(InvocationHandler.class).newInstance(proxy);
	
			return service;
	
		}
		catch(Exception ex)
		{
			//throw Exceptions.runtime(ex);
		}
		return null;
	
	}

	
}
